<?php
/* *
* 微信支付通知页面
* @code by zx
*/

//初始化xml数据，变为数组
require_once 'configMod.php';
require_once "lib/WxPay.Api.php";
require_once 'lib/WxPay.Notify.php';

@file_put_contents('v2_wxpay_log.txt', print_r($GLOBALS['HTTP_RAW_POST_DATA'],true),FILE_APPEND);


class PayNotifyCallBack extends WxPayNotify
{
	//重写回调处理函数
	public function NotifyProcess($data, &$msg)
	{
		global  $config;
		
		if ($msg == 'OK' && $data['result_code'] == 'SUCCESS') {
            // 订单号 (zx增加同一个微信不同类型的，前面加0)
            
            $data['out_trade_no'] = ltrim($data['out_trade_no'], '0');
            
            @file_put_contents('v2_wxpay_log.txt', print_r($data, true), FILE_APPEND);
            include_once ($config['webroot'] . "/module/payment/includes/payment_class.php");
            
            $payment = new payment();
            // 开店的逻辑
            if (! is_numeric($data['out_trade_no'])) {
                $cash_fee=$data['cash_fee']/100;
                return $payment->apply_shop($data['out_trade_no'], $data['transaction_id'],$cash_fee,'WXPAY');
            }
            $payment->apply_result($data['out_trade_no'], $data['transaction_id'], $data['out_trade_no']);
            return true;
        } else {
            @file_put_contents('v2_wxpay_log.txt', print_r($msg, true), FILE_APPEND);
            return false;
        }
		
	}
}

$notify = new PayNotifyCallBack();
$notify->Handle(true);//需要签名输出
